<!DOCTYPE html>
<html lang="en" class="coming-soon">
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <link type="text/css" href="__PUBLIC__/assets/plugins/iCheck/skins/minimal/blue.css" rel="stylesheet">
    <link type="text/css" href="__PUBLIC__/assets/fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link type="text/css" href="__PUBLIC__/assets/fonts/themify-icons/themify-icons.css" rel="stylesheet">
    <link type="text/css" href="__PUBLIC__/assets/css/styles.css" rel="stylesheet">

</head>

<body class="focused-form">


<div class="container" id="login-form">
    <a href="/" class="login-logo">
        <img src="__PUBLIC__/assets/img/logo-big.png">
    </a>
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2>登录</h2>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" id="validate-form" method="post" action="">
                        <div class="form-group mb-md">
                            <div class="col-xs-12">
                                <div class="input-group">
                                    <span class="input-group-addon">
                                        <i class="ti ti-email"></i>
                                    </span>
                                    <input type="email" class="form-control" placeholder="邮箱" required id="email">
                                </div>
                            </div>
                        </div>
                        <div class="form-group mb-md">
                            <div class="col-xs-12">
                                <div class="input-group">
										<span class="input-group-addon">
											<i class="ti ti-key"></i>
										</span>
                                    <input type="password" class="form-control" id="password" placeholder="密码" required>
                                </div>
                            </div>
                        </div>
                        <div class="form-group mb-md">
                            <div class="col-xs-6">
                                <div class="input-group ">
										<span class="input-group-addon">
											<i class="fa  fa-barcode"></i>
										</span>
                                    <input type="text" class="form-control input-lg" id="code" placeholder="验证码 点击图片刷新"
                                           required>
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <img src="/identifying/code?{:time()}" width="120" height="35"
                                     onclick="changeCode(this);" id="identifying-code">
                            </div>
                        </div>

                        <div class="form-group mb-n">
                            <div class="col-xs-12">
                                <a href="/reset_password" class="pull-left">忘记密码?</a>
                            </div>
                        </div>

                        <div class="form-group mb-n">
                            <div class="col-xs-12">
                                <button type="submit" class="btn btn-block btn-success">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="panel-footer">
                    <div class="clearfix">
                        <a href="/register" class="btn btn-default pull-left">注册</a>
                        <a href="/login" class="btn btn-primary pull-right">登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/assets/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/assets/plugins/bootbox/bootbox.js"></script>
<script>
    $(document).ready(function () {
        $('#validate-form').submit(function (e) {
            e.preventDefault();
            var email = $('#email');
            var password = $('#password');
            var code = $('#code');

            if (email.val().length <= 0 || password.val().length <= 0) {
                alert('参数不正确');
            } else {
                $.post('', {email: email.val(), password: password.val(), code: code.val()}, function (res) {
                    var data = JSON.parse(res);
                    if (data.success === false) {
                        bootbox.dialog({
                            message: JSON.stringify(data.data),
                            title: "登陆失败",
                            buttons: {
                                success: {
                                    label: "好的!",
                                    className: "btn-danger"
                                }
                            }
                        });
                        if (data.code === 2000) {
                            changeCode($('#identifying-code'));
                        }
                    } else {
                        window.location.reload();
                    }
                });
            }
            return false;
        });
    });

    function changeCode(el) {
        var time = new Date().getTime();
        $(el).attr('src', '/identifying/code?' + time);
    }
</script>
</body>
</html>